home *** CD-ROM | disk | FTP | other *** search
- Path: news3.digex.net!usenet
- From: Scott Stanchfield <scooter@mccabe.com>
- Newsgroups: comp.lang.c,comp.unix.programmer
- Subject: Re: Q: '\n' character
- Date: Tue, 02 Apr 1996 16:53:27 -0500
- Organization: McCabe & Associates
- Message-ID: <3161A1D7.2168@mccabe.com>
- References: <31616F63.481D@lava.weeg.uiowa.edu>
- NNTP-Posting-Host: mccabe.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 3.0b2 (X11; I; HP-UX A.09.05 9000/720)
-
- If this is a homework problem, press "delete" now...
-
- Spoiler alert... ;)
-
-
-
- How about:
-
- char text[MY_BUF_LEN];
- char *pos;
-
- if (fgets(text, MY_BUF_LEN, file))
- if (pos = strchr(text, '\n'))
- *pos = '\0';
-
- which will get the line of text (assuming it is definitely shorter than
- MY_BUF_LEN -- if not, this gets a bit trickier but is left as an
- exercise for the interested reader...), find the first newline (it will
- end the string if present), then overwrite it with an end-of-string
- null.
-
- -- Scott
-
-
- Artur Wojdat wrote:
- >
- > Hello everybody,
- > Is there a function or some sort of way that I could remove '\n'
- > charecter form the end of the string. I'm reading from two files, want to
- > form one line of text and then have it printed out to stdout. I use fgets to
- > read from the file and I noticed that it appends newline char at the end.
- > It is important that two lines of text, one from each file, will be
- > combined into one and I can't do it because the first string has '\n' added
- > to it. I'm picky becauuse the output will be used to feed another program and
- > I'm affraid that not properly formatted input may corrupt the process.
- > Any suggestions will be greatly appreciated .. Thanks, Art ...
-
- --
- Scott Stanchfield McCabe & Associates -- Columbia, Maryland
- (These are not necessarily the opinions of McCabe & Associates)
- Visit McCabe & Associates at http://www.mccabe.com
-